package com.nit.tools;

import org.apache.commons.lang3.StringUtils;

/**
 * string工具类
 *
 * @Auth: 逆天开源-逍遥哥哥
 * @link 1715656022@qq.com
 * @Date: 2023-07-11
 */
public class NitStringTools {

    public static boolean isBlank(String str) {
        return null == str || "".equals(str);
    }

    public static boolean notBlank(String str) {
        return !isBlank(str);
    }

    public static String hidePhoneNumber(String phoneNumber) {
        if (StringUtils.isEmpty(phoneNumber) || phoneNumber.length() != 11) {
            return phoneNumber; // 非法手机号码格式
        }
        return phoneNumber.substring(0, 3) + "****" + phoneNumber.substring(7);
    }

    public static String hidePhoneNumberRegex(String phoneNumber) {
        if (StringUtils.isEmpty(phoneNumber) || phoneNumber.length() != 11) {
            return phoneNumber; // 非法手机号码格式
        }
        String resultPhone = phoneNumber.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
        return resultPhone;
    }

    public static String hideEmail(String email) {
        String resultEmail = email.replaceAll("(\\w?)(\\w+)(\\w)(@\\w+\\.[a-z]+(\\.[a-z]+)?)", "$1****$3$4");
        System.out.println("隐藏后的邮箱：" + resultEmail);
        return resultEmail;
    }


    public static String hideIdCard(String idCard) {
        String resultIdCard = idCard.replaceAll("(\\d{4})\\d{10}(\\w{4})", "$1*****$2");
        System.out.println("隐藏后的身份证号：" + resultIdCard);
        return resultIdCard;
    }

}
